<?php
class BaseAction
{
    protected $uri;
    protected $http_method;
    protected $params;
    protected $input;
    protected $m;
    protected $output;

    protected function __construct($uri)
    {
        if(strtolower($_SERVER['REQUEST_METHOD']) != strtolower($this->http_method)) {
            throw HttpException('', 405, $this->output);
        }
        $this->uri  = $uri;
        $this->output = ConfLib::get('http', 'output');
        switch($this->http_method) {//todo cookie
            case 'get' :
                $this->input = $_GET;
                break;
            case 'post' :
                $this->input = $_POST;
                break;
            case 'put' :
                $this->input = file_get_contents('php://input');
                break;
        }
        $this->checkParams();
    }

    protected function checkParams()
    {
        if(empty($this->params)) {
            return true;
        }
        foreach($this->params as $one) {
            if(!isset($this->input[$one])) {
                throw new HttpException('', 400);
            }
        }
    }
    
    public function execute()
    {
        //try {
            $this->logic();
            return $this->output;
        //} catch (Exception $e) {
        //    return $this->output;
        //}
    }
}
?>
